#include <cstdio>
#include <algorithm>
#include <map>
#include <string>
#include <iostream>
using namespace std;
//new old
map<string,string> mp;
int main(void){
    int n;
    string a,b;
    scanf("%d",&n);
    getchar();
    while(n--){
        cin >> a >> b;
        if(mp.find(a)!=mp.end()){
            //cout << mp.find(a)->second << endl;
            mp[b]=mp[a];
            mp.erase(a);
        }
        else{
            mp[b]=a;
        }
        //cout << mp[b] << endl;
    }
    map<string,string>::iterator it=mp.begin();
    printf("%d\n",mp.size());
    for(;it!=mp.end();it++){
        cout << it->second <<" "<< it->first <<endl;
    }
    return 0;
}
